import { Injectable } from '@nestjs/common';
import { CreateArticleDto } from './dto/create-article.dto';
import { UpdateArticleDto } from './dto/update-article.dto';
import { PrismaService } from '../prisma/prisma.service';

@Injectable()
export class ArticleService {

  constructor(private db: PrismaService){}

  create(createArticleDto: CreateArticleDto) {
    return this.db.article.create({data:createArticleDto});
  }

  findAll() {
    return this.db.article.findMany();
  }

  findOne(id: number) {
    return this.db.article.findUnique({where:{id}})
  }

  update(id: number, updateArticleDto: UpdateArticleDto) {
    this.db.article.update({
        where:{id},
        data:updateArticleDto
    })
  }

  remove(id: number) {
    this.db.article.delete({where:{id}})
  }
}
